package com.grace.controller;

import com.grace.service.StudentService;
import com.grace.service.StudentServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/deleteStudentServlet")
public class DeleteStudentServlet extends HttpServlet {
    StudentService studentService = new StudentServiceImpl();

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String base = request.getContextPath();

        //1.获取所有id
        String[] ids = request.getParameterValues("sid");
        //2.调用service删除
        studentService.delSelectedStudent(ids);
        //3.跳转到查询所有Servlet
        response.sendRedirect(base + "/listStudentServlet");
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }
}
